package ar.edu.itba.it.paw.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import ar.edu.itba.it.paw.domain.User;
import ar.edu.itba.it.paw.domain.exceptions.InvalidOperationException;
import ar.edu.itba.it.paw.services.UserServices;
import ar.edu.itba.it.paw.services.impl.UserServicesImpl;

@SuppressWarnings("serial")
public class OpinionList  extends HttpServlet {

	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
		
		HttpSession session = req.getSession(false);
		User user =((User) session.getAttribute("usuario"));
		if(!user.isAdmin()){
			throw new InvalidOperationException();
		}
		UserServices opinion = UserServicesImpl.getInstance();
		req.setAttribute("opiniones", opinion.getAllOpinions());
		req.getRequestDispatcher("/WEB-INF/jsp/listOpinions.jsp").forward(req, resp);
		return;
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
		return;
	}

	
}
